/*
题目链接：https://leetcode.cn/problems/number-of-islands/description/
	刘沛民	2024-12-3
*/

void DFS(char **grid,int x,int y,int n,int m)
{
    if(x<0||y<0||x>=m||y>=n||grid[x][y]!='1')
    {
        return;
    }
    grid[x][y]='6';
    DFS(grid,x+1,y,n,m);
    DFS(grid,x-1,y,n,m);
    DFS(grid,x,y+1,n,m);
    DFS(grid,x,y-1,n,m);
    return;
}
int numIslands(char** grid, int gridSize, int* gridColSize) {
    int m=gridSize;
    int n=gridColSize[0];
    int sum=0;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(grid[i][j]=='1')
            {
                sum++;
                DFS(grid,i,j,n,m);
            }
        }
    }
    return sum;
}